import prettytable
from color import *


def formatAttribute(attribute):
    AttributeTable = prettytable.PrettyTable()
    # AttributeTable.set_style(PLAIN_COLUMNS)  # 样式为无边框
    AttributeTable.field_names = ["", "  ", " ", "   "]
    AttributeTable.header = False
    AttributeTable.vertical_char = " "
    AttributeTable.junction_char = "="
    AttributeTable.add_row(
        [
            f"{RED}「气血」",
            "{Hp}/{HpMax} ({PURPLE}%)".format(
                Hp=str(attribute["hp"]),
                HpMax=str(attribute["hp_max"]),
                PURPLE=str(
                    round((int(attribute['hp']) / int(attribute['hp_max']) * 100))
                ),
            )
            + NORMAL,
            f"{PURPLE}「臂力」",
            str(attribute["atk"]) + NORMAL,
        ]
    )
    AttributeTable.add_row(
        [
            f"{GRAY}「防御」",
            str(attribute["def"]) + NORMAL,
            f"{GREEN}「命中率」",
            "{dex}%".format(dex=str(attribute["dex"])) + NORMAL,
        ]
    )
    AttributeTable.add_row(
        [
            f"{CYAN}「经验」",
            str(attribute["exp"]) + "/" + str(attribute["exp_max"]) + NORMAL,
            f"{CYAN}「潜力」",
            str(attribute["pot"]) + NORMAL,
        ]
    )
    AttributeTable.add_row(
        [
            f"{BLUE}「境界」",
            str(attribute["lv"]) + NORMAL,
            f"{YELLOW}「金钱」",
            str(attribute["coin"]) + NORMAL,
        ]
    )
    AttributeTable.add_row(
        [
            f"{YELLOW}「暴击伤害」",
            "{crit_damage}%".format(crit_damage=str(100 + attribute["crit_damage"]))
            + NORMAL,
            f"{YELLOW}「暴击率」",
            "{crit}%".format(crit=str(attribute["crit"])) + NORMAL,
        ]
    )
    return AttributeTable


if __name__ == "__main__":
    attribute = {
        "hp": 100,
        "hp_max": 100,
        "def": 1,
        "atk": 1,
        "dex": 99,
        "crit": 1,
        "crit_damage": 50,
        "exp": 1,
        "exp_max": 1,
        "lv": 1,
        "pot": 1000,
        "coin": 100,
    }
    print(formatAttribute(attribute))
